<template>
  <div class="my-stat cell-item">
    <div>
      <div class="title-row">
        <div class="flex item-center">
          <div class="label-line"></div>
          <span class="title">我的统计</span>
        </div>
        <div class="line"></div>
        <div class="flex">
          <button
            class="filter-btn"
            v-on:click="onFilterStat(false)"
            v-bind:class="{active:!isToday}"
          >累计</button>
          <button
            class="filter-btn"
            v-on:click="onFilterStat(true)"
            v-bind:class="{active:isToday}"
          >今日</button>
        </div>
      </div>
      <ul class="stat-content">
        <li class="stat-li">
          <p class="stat-titl">接收</p>
          <p class="stat-num">{{statInfo.jieshou || "-"}}</p>
        </li>
        <li class="stat-li">
          <p class="stat-titl">完成</p>
          <p class="stat-num">{{statInfo.wancheng || "-"}}</p>
        </li>
      </ul>
      <div class="title-row">
        <div class="flex item-center">
          <div class="label-line"></div>
          <span class="title">上级督办</span>
        </div>
        <div class="line"></div>
      </div>
      <ul class="card-ul">
        <li class="card-list" v-for="(item,index) in dataList" :key="index">
          <div class="img-parent">
            <img src="../../assets/login/login-bg.png" alt>
          </div>
          <div class="main">
            <div class="title">{{item.eventName||'-'}}</div>
            <div class="text">
              <div class="left">
                <span>{{getTimeStr(item.createTime, "yyyy-MM-dd") || "-"}}</span>
                <span>{{item.eventStatusName}}</span>
              </div>
              <div>
                <button @click="openDialog('ProcessingDialog',{item})">反馈</button>
              </div>
            </div>
          </div>
        </li>
        <div v-if="!dataList.length" class="no-data">
          <img src="../../assets/no-data.png" alt>
        </div>
      </ul>
    </div>
  </div>
</template>

<script>
import { sortingEventinfoQueryBrandStatistics,sortingEventinfoQueryBrandPress } from "../../config/api";
import { getTimeStr,getCookie} from "../../utils";
import Pubsub from "../../utils/pubsub";
export default {
  data() {
    return {
      isToday: false, //今日—true；历史—false
      getTimeStr, 
      statInfo: {
        jieshou: '-', //接收
        wancheng: '-', //完成
      },
      dataList: [],
      request: {
        pageNum: 1,
        pageSize: 10,
        dealUnitCode:getCookie("department")&&JSON.parse(getCookie("department")).id,//所属委办局编码
      },
    };
  },
  mounted() {
    this.pubsub_token = Pubsub.subscribe("SORT_CENTER_PRESS", (type, values) => {
      // 用于督办/办结后回调执行刷新列表
      this.getDbList();
    });
      this.getStat();
      this.getDbList();
  },
  destroyed() {
    this.pubsub_token && Pubsub.unsubscribe(this.pubsub_token);
  },
  methods: {
    onFilterStat(isToday) {
      this.isToday = isToday;
      this.getStat();
    },
    /**
     * 请求统计数据
     */
    getStat() {
      sortingEventinfoQueryBrandStatistics({isToday:this.isToday,dealUnitCode:this.request.dealUnitCode}).then((result = {}) => {
        this.statInfo = result.data || {};
      });
    },
    getDbList() {//督办列表请求
      sortingEventinfoQueryBrandPress(this.request).then((res = {}) => {
        if (res.rows && res.rows.length) {
          this.dataList = res.rows;
        }
      });
    },
    openDialog(type, values) {
      console.log(values);
      	Pubsub.publish(type, values);
    },
  }
};
</script>

<style lang = "scss" scoped>
@import "../../css/unifyAcceptWorkbench.scss";
.my-stat > div {
  padding: 15px;
}
.filter-btn {
  height: 24px;
  width: 45px;
  color: #fff;
  background-color: #898989;
  &:first-child {
    margin-right: 5px;
  }
  &.active {
    background: #822424;
  }
}
.stat-content {
  padding: 10px 0;
  display: flex;
  justify-content: space-around;
  .stat-li {
    background-color: #f5f6fa;
    border-radius: 5px;
    border: solid 1px #cbd1ed;
    flex: 1;
    margin-right: 1vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 0;
    &:last-child {
      margin-right: 0;
    }
  }
  .stat-titl {
    font-size: 16px;
    color: #666;
    margin-bottom: 10px;
  }
  .stat-num {
    font-size: 22px;
    color: #ffaa00;
  }
}
.tips-title {
  color: #666;
  margin-left: 15px;
}
.card-ul {
  max-height: 194px;
  overflow: auto;
}
.card-list {
  margin-top: 10px;
  display: flex;
  padding: 15px;
  background-color: #f2f3ff;
  align-items: center;
  .img-parent {
    height: 55px;
    overflow: hidden;
    background-color: #111;
    width: 55px;
    margin-right: 18px;
    img {
      height: 100%;
      width: 100%;
    }
  }
  .main {
    flex: 1;
    .title {
      color: #1a36a9;
      margin-bottom: 14px;
    }
    .text {
      display: flex;
      justify-content: space-between;
      .left {
        font-size: 12px;
        span {
          &:last-child {
            margin-left: 50px;
            color: #ffaa00;
          }
        }
      }
      button {
        color: #fff;
        background-color: #2b88ff;
        border-radius: 3px;
        padding: 1px 10px;
      }
    }
  }
}
</style>
<style>
.my-stat .el-badge__content.is-fixed {
  background: red;
  right: 37px;
}
.my-stat .el-badge {
  height: 18px;
}
</style>
